<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑模板</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <script type="text/javascript" src="../layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/jquery.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
    <script type="text/javascript" src="../../js/commonutil.js"></script>
    <script src="./sealreplenish.js" charset="utf-8"></script>
</head>
<body>
<div class="edit-form-class" style="padding-top: 20px;">
    <form class="layui-form" id="updateSealImgForm">
        <div class="layui-form-item">
            <label class="layui-form-label">*印章名称</label>
            <div class="layui-input-block">
                <input type="text" id="sealName" name="sealName" readonly="readonly" lay-verify="required|sealNameVerify"
                       style="width: 350px" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*印章编码</label>
            <div class="layui-input-block">
                <input type="text" id="sealPwd" name="sealPwd" style="display:none;" autocomplete="off">
                <input type="text" id="sealCode" name="sealCode" readonly="readonly"
                       style="width: 350px" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*证件类型</label>
            <div class="layui-input-block" style="width: 350px">
                <input type="text" id="id" name="id" style="display:none;" autocomplete="off">
                <input type="text" id="identificationType" name="identificationType" style="display:none;" autocomplete="off">
                <input type="text" id="identificationTypeName" name="identificationTypeName" readonly="readonly" lay-verify="required|identificationTypeVerify" style="width: 350px"
                       autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*证件号码</label>
            <div class="layui-input-block">
                <input type="text" id="identificationNo"  name="identificationNo"
                       lay-verify="required|identificationNoVerify" style="width: 350px" autocomplete="off"
                       placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*法人姓名</label>
            <div class="layui-input-block">
                <input type="text" id="legalPersonName"  name="legalPersonName"
                       lay-verify="required|legalPersonNameVerify" style="width: 350px" autocomplete="off"
                       placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*法人证件类型</label>
            <div class="layui-input-block" style="width: 350px">
                <select name="legalPersonCardType" lay-filter="legalPersonCardType" id="legalPersonCardType"
                        lay-verify="required|identificationTypeVerify">
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*法人证件号码</label>
            <div class="layui-input-block">
                <input type="text" id="legalPersonId"  name="legalPersonId"
                       lay-verify="required|legalPersonIdVerify" style="width: 350px" autocomplete="off"
                       placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*企业电话</label>
            <div class="layui-input-block">
                <input type="text" id="phone"  name="phone"
                       lay-verify="required|phoneVerify" style="width: 350px" autocomplete="off"
                       placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*验证电话</label>
            <div class="layui-input-block">
                <input type="text" id="contactPhone"  name="contactPhone"
                       lay-verify="required|contactPhoneVerify" style="width: 350px" autocomplete="off"
                       placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*印章图片</label>
            <div class="layui-input-block">
                <input type="text" id="imageCode" name="imageCode" style="display:none;" autocomplete="off">
                <span id="fileName" style="color:#999"></span>
                <button type="button" class="layui-btn-primary layui-btn-lg" id="uploadImage">选择上传图片</button>
                </br></br>
                <span style="color:#999">只能上传png格式文件，文件不能超过1M（请上传透明公章）</span><br/>
                <span style="color:#999">此页面更新的图片仅更新懒猫签章图片</span>
                <input id='pictureId' name='pictureId' type="text" class="text" maxlength='50' style='display:none;'/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="padding-left: 50px;padding-top: 20px">
                <div class="layui-btn" lay-submit="" autocomplete="off" lay-filter="submitBtn" id="submitBtn">保存</div>
                <div class="layui-btn layui-btn-primary" id="closeWin">关闭</div>
            </div>
        </div>
    </form>
</div>
</body>

<script>
    jQuery(function () {
        layui.use(['laypage', 'jquery', 'layer', 'table', 'form', 'util', 'upload'], function () {
            var form = layui.form;
            var upload = layui.upload;
            debugger;
            var id = GetUrlParam("id");
            queryPersonCertType(form);
            buildEditWin(form,id);
            //文件上传
            var uploadUrl = serverPre + "/manager/scs/v2/sealInfo/upload";
            uploadFile(upload, uploadUrl);
            form.render();
        });
    });

    //提交
    $('#submitBtn').click(function () {
        layui.use(['jquery'], function () {
            var url = serverPre + "/manager/scs/v2//replenish/save";
            var formData = serializeObject($("#updateSealImgForm"));
            debugger;
            if (isBlank(formData.identificationNo)) {
                alert("统一社会信用代码证号不能为空");
                return;
            }
            if (isBlank(formData.legalPersonName)) {
                alert("法人姓名不能为空");
                return;
            }
            if (isBlank(formData.legalPersonCardType)) {
                alert("法人证件类型不能为空");
                return;
            }
            if (isBlank(formData.legalPersonId)) {
                alert("法人证件号不能为空");
                return;
            }
            if (isBlank(formData.phone)) {
                alert("企业电话不能为空");
                return;
            }
            if (isBlank(formData.contactPhone)) {
                alert("验证电话不能为空");
                return;
            }
            debugger
            var commitData = JSON.stringify({
                "id": formData.id,
                "pictureId": formData.pictureId,
                "identificationNo": formData.identificationNo,
                "legalPersonName": formData.legalPersonName,
                "legalPersonCardType": formData.legalPersonCardType,
                "phone": formData.phone,
                "contactPhone": formData.contactPhone,
                "legalPersonId": formData.legalPersonId
            });
            submitForm(commitData, url);
        })
    });

    //取消
    $("#closeWin").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    });


    function buildEditWin(form,id) {
        var url = serverPre + "/manager/scs/v2//replenish/info/" + id;
        $.ajax({
            url: url,
            type: 'GET',
            contentType: 'application/json',
            headers: {'token': getCookie('token')},
            success: function (res) {
                if (res.code === 0) {
                    var obj = res.data.vo;
                    $("#sealName").val(obj.sealName);
                    $("#id").val(obj.id);
                    $("#sealCode").val(obj.sealCode);
                    $("#legalPersonName").val(obj.legalPersonName);
                    $("#identificationType").val(obj.identificationType);
                    $("#identificationNo").val(obj.identificationNo);
                    $('select').val(obj.legalPersonCardType);
                    layui.form.render('select');
                    $("#phone").val(obj.phone);
                    $("#contactPhone").val(obj.contactPhone);
                    $("#imageCode").val(obj.ext1);
                    $("#legalPersonId").val(obj.legalPersonId);
                    $("#identificationTypeName").val("统一社会信用代码证");
                }
            },
            error: function (err) {
                errorMsg(err);
            }
        });
    }
    function queryPersonCertType(form) {
        var url = serverPre + "/manager/scs/v2/sealInfo/certType/list/p";
        var content = '<option value="">证件类型</option>'; //全局变量
        var data = JSON.stringify({'pageNo': '1', 'pageSize': '999'});
        $.ajax({
            url: url,
            data: data,
            type: 'POST',
            contentType: 'application/json',
            headers: {'token': getCookie('token')},
            success: function (res) {
                if (res.code === 0) {
                    var result = res.data.list;
                    $.each(result, function (i, item) {
                        var certType = item.code;
                        var certTypeName = item.name;
                        content += '<option value = "' + certType + '">' + certTypeName + '</option>'
                    });
                    $("#legalPersonCardType").html(content);
                    form.render('select');
                }
            },
            error: function (err) {
                errorMsg(err);
            }
        });
    }

    function isNotBlank(s) {
        return s != undefined && s != null && (s + "").trim().length > 0
    }

    function isBlank(s) {
        return !isNotBlank(s);
    }
</script>
</html>
